package com.easy.common;

import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;
import java.util.Map;

public class CommonResult implements Serializable {
    private int code;
    private String message;
    private Object data;
    private int total;

    // 默认构造函数
    public CommonResult() {
    }

    // 构造函数用于自定义 code、message 和 data
    public CommonResult(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 构造函数用于自定义 code、message、data 和 total
    public CommonResult(int code, String message, Object data, int total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    // 静态方法：成功响应，带 data 和 total
    public static CommonResult success(Object data, int total) {
        return new CommonResult(200, "Success", data, total);
    }

    // 静态方法：成功响应，带 data
    public static CommonResult success(Object data) {
        return new CommonResult(200, "Success", data);
    }

    // 静态方法：成功响应，无数据
    public static CommonResult success() {
        return new CommonResult(200, "Success", null);
    }

    // 静态方法：失败响应，带 code、message 和 data
    public static CommonResult fail(int code, String message, Object data) {
        return new CommonResult(code, message, data);
    }

    // 静态方法：失败响应，带 code 和 message
    public static CommonResult fail(int code, String message) {
        return new CommonResult(code, message, null);
    }

    // 静态方法：失败响应，无 data
    public static CommonResult fail() {
        return new CommonResult(400, "Operation failed", null);
    }

    // 静态方法：失败响应，带 message
    public static CommonResult fail(String message) {
        return new CommonResult(400, message, null);
    }

    // Getters 和 Setters
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }
    public static CommonResult success(int code, String message) {
        return new CommonResult(code, message, null);
    }
    public static CommonResult success(int code, String message, Object data) {
        return new CommonResult(code, message, data);
    }

}
